package company.permissionsystem.dao;

import company.permissionsystem.model.entity.SysPermission;
import company.permissionsystem.model.entity.SysRole;
import company.permissionsystem.model.entity.SysUser;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface AdminDao {

    @Select("select username, phone, create_time from sys_user where id in " +
            "(select user_id from sys_user_role where role_id = " +
            "(select id from sys_role where role_name = 'admin'))")
    List<SysUser> findAllAdmin();

    @Select("select * from sys_role")
    List<SysRole> findAllRole();

    @Select("select role_name from sys_role r where r.id in " +
            "(select role_id from sys_role_permission rp where rp.permission_id = #{id});")
    List<SysRole> setSysRoleNameByPermission(Long id);

    @Select("select * from sys_permission")
    List<SysPermission> findAllPermission();
}
